<?php


namespace app\shopConsole\service\tag;

use app\dao\goods\ShopTagDao;
use app\model\ShopTag;

class TagService
{
    /**
     * @var ShopTag
     */
    private ShopTag $shopTag;

    public function __construct(ShopTag $shopTag)
    {
        $this->shopTag = $shopTag ;
    }

    public function create($data)
    {
        $shopTagDao = new ShopTagDao();

        return $shopTagDao->save([
            'name'      => $data['name'],
            'shop_id'      => $data['shop_id'],
        ]);
    }

    public function update($name)
    {
        $shopTagDao = new ShopTagDao();

        $this->shopTag->update_time = time();

        if (!empty($name))
        {
            $this->shopTag->name = $name;
        }

        return $shopTagDao->update($this->shopTag->toArray(), $this->shopTag->id);
    }

    public function delete()
    {
        $shopTagDao = new ShopTagDao();
        $shopTagDao->deleteById($this->shopTag->id);

    }

}